﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>生产计划-修改领料单</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<%@ include file="../../common/jsp/autocomplete.jsp"%>
<script type="text/javascript" src="common/js/calendar/WdatePicker.js" ></script>
<script type="text/javascript" src="common/js/jquery/chinaArea/jquery.fillOptions.js"></script>
<script type="text/javascript">
var materialNamesIndex = <s:property value="mrForm.formDetails.size"/> - 1;
function addLine() {
	materialNamesIndex++;
	var table = $("#materialList");
	table.find("tr").last().before(
	           '<tr class="odd">'
	          +'<td><input type="button" value="请选择" onclick="openSelectDialog('+materialNamesIndex+')" />'
	          +'<s:hidden id="materialCodes-'+materialNamesIndex+'" name="materialCodes" />'
	          +'<s:hidden id="materialIds-'+materialNamesIndex+'" name="materialIds" /></td>'
	          +'<td><span id="materialRootCategorys-'+materialNamesIndex+'"></span>'
	          +'<s:hidden id="rootCategoryNames-'+materialNamesIndex+'" name="rootCategoryNames" /></td>'
	          +'<td><span id="materialCategorys-'+materialNamesIndex+'"></span>'
	          +'<s:hidden id="categoryNames-'+materialNamesIndex+'" name="categoryNames" /></td>'
	          +'<td><span id="materialNames-'+materialNamesIndex+'"></span></td>'
	          +'<td><span id="materialTypes-'+materialNamesIndex+'"></span></td>'
	          +'<td><span id="materialSkuNames-'+materialNamesIndex+'"></span>'
	          +'<s:hidden id="materialSkus-'+materialNamesIndex+'" name="materialSkus" /></td>'
	          +'<td><span id="materialUnits-'+materialNamesIndex+'"></span></td>'
	          +'<td><span id="acceptNumbers-'+materialNamesIndex+'"></span></td>'
	          +'<td><s:textfield id="materialNums-'+materialNamesIndex+'" name="materialNums" size="5" cssClass="{required:true,maxlength:10,number:true}"/></td>'
	          +'<td><input type="button" value="删除" class="input1" onclick="deleteLine(this)" /></td>'
	          +'</tr>');
}

function deleteLine(button, detailId) {
	if (detailId) {
		var removeDetailIds = $("#order_removeDetailIds").val();
		$("#order_removeDetailIds").val(removeDetailIds + "," + detailId);
	}
	$(button).parents("tr").remove();
}

function initBatchNoSelect(selectId) {
	$("#" + selectId).fillOptions(
			"queryNotFinishProductBatchInfoJOSN.action?temp=" + new Date(),
			{datatype:"json",text:"value",value:"value"});
}
/*
function initMaterialBatchNoSelect(selectId, materialsId) {
	$("#" + selectId).fillOptions(
			"queryNotEmptyMeterialsBatchInfoJOSN.action?materialsId=" + materialsId,
			{datatype:"json",text:"batchNo",value:"batchNo",jsonData:"batchInfoList"});

}
*/
function openSelectDialog(id) {
 	alertDialog(700, 500, "showSelectMaterialsDialog.action", 
 	function (result) {
 		var materials = result.materials;
 		if (materials) {
 			var fieldNames = "";
 			var skuId = result.skuId;
 		   	var skuConfig = materials.skuDetails;
 		   	var acceptNumber = 0;
 	 	   	for (var i in skuConfig) {
 	 	 	   	var config = skuConfig[i];
 	 	 	   	if (config.id == skuId) {
 	 	 	   		acceptNumber = config.number;
 	 	 	 	 	for (var j in config.fields) {
 	  	   				var field = config.fields[j];
 	  	   				fieldNames += field.customName + " ";
 	 	 	 	 	}
 	 	 	 	 	break;
 	 	 	   	}
 	 	   	}
 	 	   	$("#materialCodes-" + id).val(materials.code);
 	 	    $("#materialIds-" + id).val(skuId);
 			$("#materialRootCategorys-" + id).html(materials.rootCategory.name);
 			$("#rootCategoryNames-" + id).val(materials.rootCategory.name);
 			$("#materialCategorys-" + id).html(materials.category.name);
 			$("#categoryNames-" + id).val(materials.category.name);
 			$("#materialNames-" + id).html(materials.name);
 			$("#materialTypes-" + id).html(materials.type);
 			$("#materialSkuNames-" + id).html(fieldNames);
 			$("#materialSkus-" + id).val(fieldNames);
 			$("#materialUnits-" + id).html(materials.units);
 			$("#acceptNumbers-" + id).html(acceptNumber);
 		}
 	});
}

$(document).ready(function() {
	$("#saveMaterialRequisiteForm").validate();
	initBatchNoSelect("mrForm_planNo");
	$("#mrForm_planNo").val('<s:property value="mrForm.planNo"/>');
});
</script>
</HEAD>
<BODY>
    <s:form action="saveMaterialRequisiteForm">
    <s:hidden name="mrForm.id" />
    <s:hidden name="mrForm.type" />
    <s:hidden name="mrForm.status" />
    <s:hidden id="order_removeDetailIds" name="mrForm.removeDetailIds" />
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">生产计划</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">修改领料单</span></td>
		  </tr>
		</table>
      </div>
     <div class="main_1">
       <table width="99%" border="0" cellpadding="5" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="2">领料单信息</td>
         </tr>
         <tr>
		    <td width="19%" bgcolor="#FAFAFA" align="right"><strong>领料日期</strong></td>
		    <td width="81%" bgcolor="#FAFAFA">
				<s:textfield name="mrForm.createDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" size="10" cssClass="{required:true}"/>
			</td>
		 </tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>部门</strong></td>
	      <td bgcolor="#FAFAFA">
       	     <s:select name="mrForm.deptId"
       	        list="departmentList"
        		listKey="id"
        		listValue="value"
        		headerKey="-1"
        		headerValue="-请选择-"
       	 	    cssClass="{selected:true}" />
			<span class="red-text1">*</span>
		  </td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>生产批号</strong></td>
	      <td bgcolor="#FAFAFA">
       	     <s:select id="mrForm_planNo" name="mrForm.planNo" list="#{'-1':'-请选择-'}" cssClass="{selected:true}"/>
			<span class="red-text1">*</span>
		  </td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>经办人</strong></td>
	      <td bgcolor="#FAFAFA">
			<s:textfield name="mrForm.person" size="10" cssClass="{required:true,maxlength:10}"/>
			<span class="red-text1">*</span>
		  </td>
		</tr>
       </table>
     </div>
     <div class="clear"></div>
	 <div class="main_scroll">
       <table width="900px" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a" id="materialList">
        <tr class="ksglxx2bg">
          <th width="60px" >&nbsp;</th>
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
          <th width="180px" >其他</th>
		  <th width="50px">单位</th>
		  <th width="65px" >仓库数量</th>
		  <th width="65px">领用数量<span class="red-text1">*</span></th>
		  <th align="left">&nbsp;</th>
		</tr>
		<s:iterator value="mrForm.formDetails" id="detail" status="st">
        <tr class="odd">
          <td><input type="button" value="请选择" onclick='openSelectDialog(<s:property value="#st.index" />)' />
              <s:hidden id="materialCodes-%{#st.index}" name="materialCodes" value="%{#detail.materialNo}" />
              <s:hidden id="materialIds-%{#st.index}" name="materialIds" value="%{#detail.materialId}" />
          </td>
          <td><span id='materialRootCategorys-<s:property value="#st.index" />'><s:property value="#detail.materialRootCategory" /></span>
              <s:hidden id='rootCategoryNames-%{#st.index}' name="rootCategoryNames" value="%{#detail.materialRootCategory}" /></td>
          <td><span id='materialCategorys-<s:property value="#st.index" />'><s:property value="#detail.materialCategory" /></span>
              <s:hidden id='categoryNames-%{#st.index}' name="categoryNames" value="%{#detail.materialCategory}" /></td>
          <td><span id='materialNames-<s:property value="#st.index" />'><s:property value="#detail.materialName" /></span></td>
          <td><span id='materialTypes-<s:property value="#st.index" />'><s:property value="#detail.materialType" /></span></td>
          <td><span id='materialSkuNames-<s:property value="#st.index" />'><s:property value="#detail.materialSku" /></span>
              <s:hidden id="materialSkus-%{#st.index}" name="materialSkus" value="%{#detail.materialSku}" /></td>
          <td><span id='materialUnits-<s:property value="#st.index" />'><s:property value="#detail.unit" /></span></td>
    	  <td>&nbsp;</td>
    	  <td><s:textfield id='materialNums-%{#st.index}' name="materialNums" value="%{#detail.number}" size="5" 
					cssClass="{required:true,maxlength:10,number:true}"/></td>
          <td>
            <s:hidden name="detailIds" value="%{#detail.id}" />
            <input type="button" value="删除" class="input1" onclick='deleteLine(this, <s:property value="#detail.id" />)' />
          </td>
	    </tr>
	    </s:iterator>
        <tr>
         <td colspan="3" align="left" valign="top">
           <input type="button" value="添加" class="input1" onclick="addLine()" />
         </td>
        </tr>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="45%" align="right">
			   <s:submit value="保存" cssClass="input1" />&nbsp;&nbsp;
			   <input type="button" value="关闭" class="input1" onclick='javascript:window.location.href="materialRequisiteFormList.action"' /></td>
			 <td width="55%" align="left"></td>
		   </tr>
	   </table>
	</div>
	<div class="clear"></div>
	</s:form>
</BODY></HTML>
